﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace Assignment3.Objects3D
{
    class WallBlock : SymmetricObject
    {
        private BoundingBox wallBorder;

        public WallBlock(Vector3 Size, Vector3 Position)
            : base(new Vector3(Size.X, Size.Y, Size.Z), Position, 6, 2)
        {            
            wallBorder = new BoundingBox(new Vector3(0, 0, -Size.Z) + Position, new Vector3(Size.X, Size.Y, 0) + Position);
        }

        public BoundingBox WallBorder
        {
            get { return this.wallBorder; }
        }

        public override void BuildShape()
        {
            //8 Vertices of the cube
            Vector3[] faceVertices = new Vector3[8];
            faceVertices[0] = new Vector3(0, Size.Y, 0) + Position;
            faceVertices[1] = new Vector3(Size.X, Size.Y, 0) + Position;
            faceVertices[2] = Vector3.Zero + Position;
            faceVertices[3] = new Vector3(Size.X, 0, 0) + Position;
            faceVertices[4] = new Vector3(0, Size.Y, -Size.Z) + Position;
            faceVertices[5] = new Vector3(Size.X, Size.Y, -Size.Z) + Position;
            faceVertices[6] = new Vector3(0, 0, -Size.Z) + Position;
            faceVertices[7] = new Vector3(Size.X, 0, -Size.Z) + Position;

            Vector2[] textureVertices = new Vector2[4];
            textureVertices[0] = new Vector2(0, 0);
            textureVertices[1] = new Vector2(1, 0);
            textureVertices[2] = new Vector2(0, 1);
            textureVertices[3] = new Vector2(1, 1);

            //front face    
            Faces[0][0] = new VertexPositionNormalTexture(faceVertices[0], Vector3.UnitZ, textureVertices[0]);
            Faces[0][1] = new VertexPositionNormalTexture(faceVertices[1], Vector3.UnitZ, textureVertices[1]);
            Faces[0][2] = new VertexPositionNormalTexture(faceVertices[2], Vector3.UnitZ, textureVertices[2]);
            Faces[0][3] = new VertexPositionNormalTexture(faceVertices[1], Vector3.UnitZ, textureVertices[1]);
            Faces[0][4] = new VertexPositionNormalTexture(faceVertices[3], Vector3.UnitZ, textureVertices[3]);
            Faces[0][5] = new VertexPositionNormalTexture(faceVertices[2], Vector3.UnitZ, textureVertices[2]);

            //back face
            Faces[2][0] = new VertexPositionNormalTexture(faceVertices[4], -Vector3.UnitZ, textureVertices[0]);
            Faces[2][1] = new VertexPositionNormalTexture(faceVertices[6], -Vector3.UnitZ, textureVertices[2]);
            Faces[2][2] = new VertexPositionNormalTexture(faceVertices[5], -Vector3.UnitZ, textureVertices[1]);
            Faces[2][3] = new VertexPositionNormalTexture(faceVertices[6], -Vector3.UnitZ, textureVertices[2]);
            Faces[2][4] = new VertexPositionNormalTexture(faceVertices[7], -Vector3.UnitZ, textureVertices[3]);
            Faces[2][5] = new VertexPositionNormalTexture(faceVertices[5], -Vector3.UnitZ, textureVertices[1]);

            //Right face     
            Faces[1][0] = new VertexPositionNormalTexture(faceVertices[1], Vector3.UnitX, textureVertices[0]);
            Faces[1][1] = new VertexPositionNormalTexture(faceVertices[5], Vector3.UnitX, textureVertices[2]);
            Faces[1][2] = new VertexPositionNormalTexture(faceVertices[3], Vector3.UnitX, textureVertices[1]);
            Faces[1][3] = new VertexPositionNormalTexture(faceVertices[5], Vector3.UnitX, textureVertices[2]);
            Faces[1][4] = new VertexPositionNormalTexture(faceVertices[7], Vector3.UnitX, textureVertices[3]);
            Faces[1][5] = new VertexPositionNormalTexture(faceVertices[3], Vector3.UnitX, textureVertices[1]);

            //left face
            Faces[3][0] = new VertexPositionNormalTexture(faceVertices[4], -Vector3.UnitX, textureVertices[0]);
            Faces[3][1] = new VertexPositionNormalTexture(faceVertices[0], -Vector3.UnitX, textureVertices[2]);
            Faces[3][2] = new VertexPositionNormalTexture(faceVertices[6], -Vector3.UnitX, textureVertices[1]);
            Faces[3][3] = new VertexPositionNormalTexture(faceVertices[0], -Vector3.UnitX, textureVertices[2]);
            Faces[3][4] = new VertexPositionNormalTexture(faceVertices[2], -Vector3.UnitX, textureVertices[3]);
            Faces[3][5] = new VertexPositionNormalTexture(faceVertices[6], -Vector3.UnitX, textureVertices[1]);


            //Top face            
            Faces[4][0] = new VertexPositionNormalTexture(faceVertices[0], -Vector3.UnitY, textureVertices[2]);
            Faces[4][1] = new VertexPositionNormalTexture(faceVertices[4], -Vector3.UnitY, textureVertices[3]);
            Faces[4][2] = new VertexPositionNormalTexture(faceVertices[1], -Vector3.UnitY, textureVertices[0]);
            Faces[4][3] = new VertexPositionNormalTexture(faceVertices[4], -Vector3.UnitY, textureVertices[3]);
            Faces[4][4] = new VertexPositionNormalTexture(faceVertices[5], -Vector3.UnitY, textureVertices[1]);
            Faces[4][5] = new VertexPositionNormalTexture(faceVertices[1], -Vector3.UnitY, textureVertices[0]);

            //Bottom face
            Faces[5][0] = new VertexPositionNormalTexture(faceVertices[3], Vector3.UnitY, textureVertices[1]);
            Faces[5][1] = new VertexPositionNormalTexture(faceVertices[2], Vector3.UnitY, textureVertices[2]);
            Faces[5][2] = new VertexPositionNormalTexture(faceVertices[6], Vector3.UnitY, textureVertices[0]);
            Faces[5][3] = new VertexPositionNormalTexture(faceVertices[6], Vector3.UnitY, textureVertices[2]);
            Faces[5][4] = new VertexPositionNormalTexture(faceVertices[7], Vector3.UnitY, textureVertices[3]);
            Faces[5][5] = new VertexPositionNormalTexture(faceVertices[3], Vector3.UnitY, textureVertices[1]);
        }
    }
}